package org.example;

import java.util.ArrayList;
import java.util.List;

public class Test2 {
    List<List<Integer>> ret;
    List<Integer> path;
    public List<List<Integer>> combine(int n, int k) {
        ret = new ArrayList<>();
        path = new ArrayList<>();
        dfs(n,k,1);
        return ret;
    }

    private void dfs(int n, int k, int index) {
        if (path.size() == k) {
            ret.add(new ArrayList<>(path));
            return;
        }
        for (int i = index; i <= n; i++) {
            path.add(i);
            dfs(n,k,i + 1);
            path.remove(path.size() - 1);
        }
    }
}
